package com.nbrc.uil;

import java.io.InputStream;

import org.activiti.engine.impl.interceptor.Command;
import org.activiti.engine.impl.interceptor.CommandContext;

public class HistoryProcessInstanceDiagramCmd implements Command<InputStream> {
    protected String historyProcessInstanceId;
    protected InputStream is;
    public HistoryProcessInstanceDiagramCmd(String historyProcessInstanceId) {
        this.historyProcessInstanceId = historyProcessInstanceId;
    }

    public HistoryProcessInstanceDiagramCmd(InputStream is,
			String processInstanceId) {
		this.is = is;
		this.historyProcessInstanceId = processInstanceId;
	}

	public InputStream execute(CommandContext commandContext) {
        try {
            CustomProcessDiagramGenerator customProcessDiagramGenerator = new CustomProcessDiagramGenerator();

            return customProcessDiagramGenerator
                    .generateDiagram(is,historyProcessInstanceId);
        } catch (Exception ex) {
          //  throw new RuntimeException(ex);
        	if(is!=null){
        		return is;
        	}else{
        		throw new RuntimeException(ex);
        	}
        }
    }
}
